package v2.parser

/**
 * @author bweber
 * @version $Rev$, $Date$
 */

trait Attributed {
  
  var attrdefs:List[Attr]
  
  def listAttributeNames() = {
    var names = List[String]() 
    for ( attr <- attrdefs ) {
      names = attr.name :: names
    }
    names
  }
  
  def addAttribute(name:String,typeref:TypeRef):Attributed = {
    attrdefs = Attr(name,typeref) :: attrdefs
    this
  }
  
  def removeAttribute(name:String):Attributed = {
    for ( attr <- attrdefs ) {
      if ( attr.name == name ) {
        attrdefs = attrdefs - attr
        return this
      }
    }
    throw new RuntimeException("No such attribute " + name + " to remove")
  }
  
  def hasAttribute(name:String):Boolean = {
    for ( attr <- attrdefs ) {
      if ( attr.name == name ) {
        return true
      }
    }
    return false
  }
  
  def getAttribute(name:String):Attr = {
    for ( attr <- attrdefs ) {
      if ( attr.name == name ) {
        return attr
      }
    }
    throw new RuntimeException("No such attribute: " + name)
  }
  
}